package EA.testproblems;
import EA.*;

/**

<table border="0" cellpadding="2" cellspacing="0">
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem description</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top" width="200"><b>Name:</b></td>
  <td valign="top">SchafferTilted F6</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Nickname:</b></td>
  <td valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Intended usage:</b></td>
  <td valign="top">Harder test for global optimization. The problems contains
  "minimum rings" around the global minima with almost the same fitness as
  the global minima.
</td>
</tr>

<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Problem details</b></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Function:</b></td>
  <td valign="top">0.5 + (sin<sup>2</sup>(sqrt(x<sup>2</sup> + y<sup>2</sup>)) - 0.5)/((1 + 0.001(x<sup>2</sup> + y<sup>2</sup>))<sup>2</sup>)+ 0.0005*x + 0.0002*y
</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Plots:</b></td>
  <td valign="top"><img src="../../images/testproblems/schaffertiltedf6.gif">&nbsp;&nbsp;
<img src="../../images/testproblems/schaffertiltedf6_contour.gif"></td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Ranges:</b></td>
  <td valign="top">x = [-100:100]&nbsp;&nbsp;y = [-100:100] </td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Type:</b></td>
  <td valign="top">Minimization</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of maximas:</b></td>
  <td valign="top">?</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>No. of minimas:</b></td>
  <td valign="top">More than 10</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optimum radius:</b></td>
  <td valign="top">0.15
</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Optimum descriptions:</b></td>
  <td valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#e0e0e0">
  <td valign="top"><b>Known optimums:</b></td>
  <td valign="top"><br><font size=1>Capital letters 
means that the precise optimum is known, lowercase letters is the best known 
so far.</font></td>
</tr>
<tr>
  <td colspan="2" valign="top">&nbsp;</td>
</tr>
<tr bgcolor="#a0a0a0">
  <td colspan="2" valign="top"><b>Plotting details</b></td>
</tr>

<tr bgcolor="#e0e0e0">
  <td valign="top"><b>GNUPlot code:</b></td>
  <td valign="top">
  set hidden3d<br>
  set isosamples 40<br>
  set view 70,15<br>
  splot [-100:100] [-100:100] 0.5 + ((sin(sqrt(x*x + y*y)))**2 - 0.5)/((1 + 0.001*(x*x + y*y))**2)+ 0.0005*x + 0.0002*y
</td>

</tr>

</table>

*/
public class SchafferTiltedF6 extends NumericalProblem
{

  // Easier way to build max
  private double[][] lmax =  new double[0][2];
  private double[][] lmin =  {{-.2497502619e-3, -.9990010474e-4},
			      {-2.914264700, -1.165705880}, 
			      {-5.828453962, -2.331381585}, 
			      {-8.742952850, -3.497181140},
			      {-11.65784848, -4.663139390},  
			      {-14.57317585, -5.829270339},
			      {-17.48892647, -6.995570588}, 
			      {-20.40506300, -8.162025201}, 
			      {-23.32153394, -9.328613576},
			      {-26.23828492, -10.49531397}, 
			      {-29.15526585, -11.66210634}};
  public SchafferTiltedF6()
    {
      super();

      double[] optimums;

      name = "SchafferTilted F6";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  return 0.5 + (Math.pow((Math.sin(Math.sqrt(realpos[0]*realpos[0] + realpos[1]*realpos[1]))),2) - 0.5)/(Math.pow((1 + 0.001*(realpos[0]*realpos[0] + realpos[1]*realpos[1])),2))+ 0.0005*realpos[0] + 0.0002*realpos[1];

	      };
	  };

      dimensions = 2;
      ismaximization = false;
      optimumradius = 0.2;

      intervals = new Interval[2];
      intervals[0] = new Interval(-100, 100);
      intervals[1] = new Interval(-100, 100);

      // Set up known maximas
      knownmaxima = new NumericalOptimum[lmax.length];

      for (int i=0;i<lmax.length;i++) {
	optimums = new double[dimensions];
	optimums[0] = lmax[i][0];
	optimums[1] = lmax[i][1];
	knownmaxima[i] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), true, false, i);
      }

      // Set up known minimas
      knownminima = new NumericalOptimum[lmin.length];

      for (int i=0;i<lmin.length;i++) {
	optimums = new double[dimensions];
	optimums[0] = lmin[i][0];
	optimums[1] = lmin[i][1];
	knownminima[i] = new NumericalOptimum(optimums, objectivefunction.calcFitness(optimums), false, true, i);
      }
    }
}
